<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router_3.0.2.js"></script>

</head>
<body>
<div id="div1">
    <router-link to="/users" >用户模块</router-link>
    <router-link to="/products" >商品模块</router-link>
    <!-- 占位符: 显示点击的组件对应的模板内容 -->
    <router-view></router-view>    <!--占位符，会被routes数组里面的component代替-->
</div>
<script>
    const user_con = {
        template: '<h1>用户模块</h1>'

    }

    const products = {
        template:` <div>
                        <h1>商品模块</h1>
                           <router-link to="/products_children1" >家电模块</router-link>
                            <router-link to="/products_children2" >厨具模块</router-link>
                            <router-view></router-view>
                    </div>`
    }

    /*
    *   商品模块的子模块
    * */
    const products_children1 = {
        template: '<h1>家电</h1>'
    }

    const products_children2 = {
        template: '<h1>厨具</h1>'
    }



    // 创建路由对象
    const router = new VueRouter({
        /*
          配置路由规则
            通过path来映射 路径 -> 组件

            重定向：当前A路径的时候，显示B路径对应的内容

            /  当什么都不点击的时候，可以用来做初始化显示
         */
        routes: [
            {path: '/', redirect: '/users'},
            {path: '/users', component: user_con},
            {path: '/products', component: products,children:[
                    {path: '/products_children1', component: products_children1},
                    {path: '/products_children2', component: products_children2}
                ]},

        ]
    })

    const vm = new Vue({
        el: '#div1',
        data: {},
        // 挂载路由对象
        // router:router 写法一
        router

    })
</script>
</body>
</html>